/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package SimpleQM.impl;

import SimpleQM.QoS;
import SimpleQM.QoSCharacteristic;
import SimpleQM.QoSType;
import SimpleQM.SimpleQMPackage;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Qo S</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link SimpleQM.impl.QoSImpl#getType <em>Type</em>}</li>
 *   <li>{@link SimpleQM.impl.QoSImpl#getCharacteristic <em>Characteristic</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class QoSImpl extends EObjectImpl implements QoS {
	/**
	 * The default value of the '{@link #getType() <em>Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getType()
	 * @generated
	 * @ordered
	 */
	protected static final QoSType TYPE_EDEFAULT = QoSType.OFFERED;

	/**
	 * The cached value of the '{@link #getType() <em>Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getType()
	 * @generated
	 * @ordered
	 */
	protected QoSType type = TYPE_EDEFAULT;

	/**
	 * The cached value of the '{@link #getCharacteristic() <em>Characteristic</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCharacteristic()
	 * @generated
	 * @ordered
	 */
	protected QoSCharacteristic characteristic;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected QoSImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return SimpleQMPackage.Literals.QO_S;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public QoSType getType() {
		return type;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setType(QoSType newType) {
		QoSType oldType = type;
		type = newType == null ? TYPE_EDEFAULT : newType;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SimpleQMPackage.QO_S__TYPE, oldType, type));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public QoSCharacteristic getCharacteristic() {
		return characteristic;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetCharacteristic(QoSCharacteristic newCharacteristic, NotificationChain msgs) {
		QoSCharacteristic oldCharacteristic = characteristic;
		characteristic = newCharacteristic;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, SimpleQMPackage.QO_S__CHARACTERISTIC, oldCharacteristic, newCharacteristic);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setCharacteristic(QoSCharacteristic newCharacteristic) {
		if (newCharacteristic != characteristic) {
			NotificationChain msgs = null;
			if (characteristic != null)
				msgs = ((InternalEObject)characteristic).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - SimpleQMPackage.QO_S__CHARACTERISTIC, null, msgs);
			if (newCharacteristic != null)
				msgs = ((InternalEObject)newCharacteristic).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - SimpleQMPackage.QO_S__CHARACTERISTIC, null, msgs);
			msgs = basicSetCharacteristic(newCharacteristic, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SimpleQMPackage.QO_S__CHARACTERISTIC, newCharacteristic, newCharacteristic));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case SimpleQMPackage.QO_S__CHARACTERISTIC:
				return basicSetCharacteristic(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case SimpleQMPackage.QO_S__TYPE:
				return getType();
			case SimpleQMPackage.QO_S__CHARACTERISTIC:
				return getCharacteristic();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case SimpleQMPackage.QO_S__TYPE:
				setType((QoSType)newValue);
				return;
			case SimpleQMPackage.QO_S__CHARACTERISTIC:
				setCharacteristic((QoSCharacteristic)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case SimpleQMPackage.QO_S__TYPE:
				setType(TYPE_EDEFAULT);
				return;
			case SimpleQMPackage.QO_S__CHARACTERISTIC:
				setCharacteristic((QoSCharacteristic)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case SimpleQMPackage.QO_S__TYPE:
				return type != TYPE_EDEFAULT;
			case SimpleQMPackage.QO_S__CHARACTERISTIC:
				return characteristic != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (type: ");
		result.append(type);
		result.append(')');
		return result.toString();
	}

} //QoSImpl
